package org.vgr.module.actions;

import java.util.List;
import org.alfresco.service.namespace.QName;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;

public class ChangeCreatedByAction extends ActionExecuterAbstractBase{
	
	private NodeService nodeService;
	
	/**
	 * Set the node service
	 *
	 * @param nodeService  the node service
	 */
	public void setNodeService(NodeService nodeService)
	{
		this.nodeService = nodeService;
	}

	@Override
	protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
		System.out.println("CHANGING!!");
		if (this.nodeService.exists(actionedUponNodeRef) == true)
		{
			String createdBy = (String)this.nodeService.getProperty(actionedUponNodeRef, QName.createQName("{vgr.model}docCreatedBy"));
			System.out.println(createdBy);
			this.nodeService.setProperty(actionedUponNodeRef, QName.createQName("{http://www.alfresco.org/model/content/1.0}creator"), createdBy);
		}
	}

	@Override
	protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
		// TODO Auto-generated method stub
		
	}

}
